package com.ruoyi.project.emr.controller;

import java.util.List;

import com.ruoyi.project.emr.domain.EmrRecordInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.emr.domain.EmrMedicalRecord;
import com.ruoyi.project.emr.service.IEmrMedicalRecordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 病历Controller
 *
 * @author gzu
 * @date 2023-07-22
 */
@RestController
@RequestMapping("/emr/record")
public class EmrMedicalRecordController extends BaseController
{
    @Autowired
    private IEmrMedicalRecordService emrMedicalRecordService;


    /**
     * 查询病历的关联信息
     * @param recordInfo
     * @return
     */
    @GetMapping("/recordInfo")
    public TableDataInfo getRecordInfo(EmrRecordInfo recordInfo) {
        startPage();
        List<EmrRecordInfo> list = emrMedicalRecordService.selectRecordInfo(recordInfo);
        return getDataTable(list);
    }

    /**
     * 查询病人的所有病历列表
     * @param id
     * @return
     */
    @GetMapping("/listByPatientId/{id}")
    public TableDataInfo listByPatientId(@PathVariable("id") String id)
    {
        startPage();
        List<EmrMedicalRecord> list = emrMedicalRecordService.selectEmrMedicalRecordListByPatientId(id);
        return getDataTable(list);
    }


    /**
     * 查询病历列表
     */
    @GetMapping("/list")
    public TableDataInfo list(EmrMedicalRecord emrMedicalRecord)
    {
        startPage();
        List<EmrMedicalRecord> list = emrMedicalRecordService.selectEmrMedicalRecordList(emrMedicalRecord);
        return getDataTable(list);
    }

    /**
     * 获取病历详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(emrMedicalRecordService.selectEmrMedicalRecordById(id));
    }

    /**
     * 新增病历
     */
    @PostMapping
    public AjaxResult add(@RequestBody EmrMedicalRecord emrMedicalRecord)
    {
        return toAjax(emrMedicalRecordService.insertEmrMedicalRecord(emrMedicalRecord));
    }

    /**
     * 修改病历
     */
    @PutMapping
    public AjaxResult edit(@RequestBody EmrMedicalRecord emrMedicalRecord)
    {
        return toAjax(emrMedicalRecordService.updateEmrMedicalRecord(emrMedicalRecord));
    }

    /**
     * 删除病历
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(emrMedicalRecordService.deleteEmrMedicalRecordByIds(ids));
    }
}
